package com.cugmarket.controller.chat;

import com.cugmarket.dto.Result;
import com.cugmarket.entity.ChatMessage;
import com.cugmarket.service.ChatMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/chat/message")
public class ChatMessageController {
    @Autowired
    private ChatMessageService chatMessageService;

    /**
     * 根据聊天列表ID查询聊天消息
     * @param chatListId
     * @return
     */
    @GetMapping("/{chatListId}")
    public Result<List<ChatMessage>> getChatMessageList(@PathVariable("chatListId") String chatListId) {
        List<ChatMessage> list =  chatMessageService.getChatMessageList(chatListId);
        return Result.success(list);
    }

    /**
     * 更新聊天消息为已读
     * @param chatListId
     * @return
     */
    @PutMapping("/{chatListId}")
    public Result updateChatMessageIsRead(@PathVariable("chatListId") String chatListId) {
        chatMessageService.updateChatMessageIsRead(chatListId);
        return Result.success();
    }
}
